/************************************************************************************
**  
* @copyright (c) 2015-, Technology Co., LTD. All Right Reserved.
*
*************************************************************************************/
/**
* @file     duye_cap_packet.h
* @version     
* @brief      
* @author   
* @date     2013-01-08
* @note 
*
*  1. 2018-01-08 created this file
* 
*/
#pragma once

#include <duye_type.h>
#include <duye_smart_ptr.h>
#include <duye_cap_protocol.h>
#include <duye_cap_protocol_header.h>
#include <duye_cap.h>

namespace duye {

/**
 * @brief packet structure
 */
class Packet {
public:
	Packet();
	~Packet();

	bool parserPkt(uint8* data, const uint32 dataLen);

	void setPcapPkthdr(const PcapPkthdr& hdr);
	const PcapPkthdr& getPcapPkthdr() const;

	void setPktTime(const uint64 pktTime);
	uint64 getPktTime() const;

	void setRawData(uint8* data);
	const uint8* getRawData();

	void setRawDataLen(uint32 len);
	uint32 getRawDataLen();

	const LinkLayerHeader* getLinkLayerHeader();
	const NetLayerHeader* getNetLayerHeader();
	const TfLayerHeader* getTfLayerHeader();

	uint8* getSrcMac() const;
	uint8* getDstMac() const;

	uint32 getSrcIP() const;
	uint32 getDstIP() const;

	uint16 getSrcPort() const;
	uint16 getDstPort() const;

	ProtocolType getLinkLayerProto() const;
	ProtocolType getNetLayerProto() const;
	ProtocolType getTfLayerProto() const;

	bool cache();

private:
	PcapPkthdr m_pcapPkthdr;
	uint64 m_pktTime; // microsecond
	uint8* m_rawData;
	uint32 m_rawDataLen;
	LinkLayerHeader* m_linkLayerHeader;
	NetLayerHeader* m_netLayerHeader;
	TfLayerHeader* m_tfLayerHeader;
	uint8* m_data;
};

typedef SmartPtr<Packet> PacketReference;

}
